package com.huluobo.a2307douyindemo.adapter

import android.animation.ObjectAnimator
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2307douyindemo.R
import com.huluobo.a2307douyindemo.utils.ImageUtils
import com.huluobo.lib_base.bean.VideoBean
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 *  Created by LC on 2025/9/18.
 *  多布局的adapter
 */
class MultiVideoAdapter : BaseMultiItemQuickAdapter<VideoBean, BaseViewHolder>() {
    //初始化的时候识别不同的布局
    init {
        //根据类型赋值不同的布局
        addItemType(0, R.layout.item_videos)
        addItemType(1, R.layout.item_videos_live)
        addItemType(2, R.layout.item_videos_full)
    }

    override fun convert(holder: BaseViewHolder, item: VideoBean) {
        //获取视频播放器
        val player = holder.getView<StandardGSYVideoPlayer>(R.id.item_videos_player)
        //设置播放器返回按钮消失
        player.backButton.visibility = View.GONE
        //设置播放地址,播放地址,边缓存边播放,视频标题
        player.setUp(item.videopath, true, "")

        //左下角赋值
        if (item.address.isNullOrEmpty()) {
            holder.setText(R.id.item_videos_address_tv, "定位失败")
        } else {
            holder.setText(R.id.item_videos_address_tv, item.address)
        }
        holder.setText(R.id.item_videos_time_tv, item.publishtime)
        holder.setText(R.id.items_videos_authname_tv, item.authname)
        holder.setText(R.id.items_videos_caption_tv, item.caption)
        holder.setText(R.id.items_videos_pao_tv, "${item.authname}的原创作品")

        if (item.type != 1) {
            //头像
            ImageUtils.loadCircleImage(context, item.headpath, holder.getView(R.id.item_videos_header_iv))
            //是否显示关注
            if (item.guanzhu == 0) {
                holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.VISIBLE
            } else {
                holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.GONE
            }

            //否是点赞
            if (item.dianzan == 0) {
                holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuan)
            } else {
                holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuanred)
            }

            val musicPlayer = holder.getView<ImageView>(R.id.item_videos_music_player_iv)
            ImageUtils.loadCircleImage(context, item.headpath, musicPlayer)

            val animator = ObjectAnimator.ofFloat(musicPlayer, "Rotation", 0f, 360f)
            animator.duration = 3000
            animator.repeatCount = -1
            animator.interpolator = LinearInterpolator()
            animator.start()
        }
    }
}